
package com.zf.wms.purview.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: Mine
 * @CreateDate: 2019/10/11
 * @email: 1943511692@qq.com
 * @Version: 1.0.0
 */
public class ResultMap extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    private Map<String, Object> map = new HashMap<>();

    public ResultMap() {
        put("code", 0);
        put("msg", "success");
        put("data", map);
    }

    public static ResultMap error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static ResultMap error(String msg) {
        return error(500, msg);
    }

    public static ResultMap error(int code, String msg) {
        ResultMap resultMap = new ResultMap();
        resultMap.put("code", code);
        resultMap.put("msg", msg);
        return resultMap;
    }

    public static ResultMap ok(String msg) {
        ResultMap resultMap = new ResultMap();
        resultMap.put("msg", msg);
        return resultMap;
    }

    public static ResultMap ok(Object o) {
        ResultMap resultMap = new ResultMap();
        resultMap.put("data", o);
        return resultMap;
    }

    public static ResultMap ok() {
        return new ResultMap();
    }

    public Integer getCode() {
        return (Integer) this.get("code");
    }

    @Override
    public ResultMap put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public ResultMap putInside(String key, Object o) {
        map.put(key, o);
        return this;
    }
}
